package com.cyj.service.shop.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyj.dto.SearchDto;
import com.cyj.mapper.ShopMapper;
import com.cyj.mapper.UserMapper;
import com.cyj.pojo.Shop;

import com.cyj.service.shop.ShopService;
import com.cyj.utils.TokenUtil;
import com.cyj.utils.response.JsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cyj
 * @since 2022-04-20
 */
@Service
public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements ShopService {

    @Autowired
    ShopMapper shopMapper;
    @Autowired
    UserMapper userMapper;



    @Override
    public JsonObject<Shop> queryShopList(SearchDto searchDto) {
        System.out.println("检测="+searchDto.getKeyword().length());
        JsonObject jsonObject=new JsonObject();
        QueryWrapper<Shop> wrapper=new QueryWrapper<>();
        if(searchDto.getKeyword().length()>0){
            wrapper.eq("item",searchDto.getKeyword());
        }
        List<Shop> list=shopMapper.selectList(wrapper);
        Page<Shop> page=new Page<>(searchDto.getPage(),searchDto.getSize());
        List<Shop> result=  shopMapper.selectPage(page,wrapper).getRecords();
        page.getRecords().forEach(System.out::println);
        System.out.println(page.getTotal());
        jsonObject.setData(result);
        jsonObject.setCount((long)list.size());
        return jsonObject;
    }

    @Override
    public int add(Shop shop){
        return baseMapper.insert(shop);
    }

    @Override
    public int delete(Long id){
        return baseMapper.deleteById(id);
    }

    @Override
    public int updateData(Shop shop){
        return baseMapper.updateById(shop);
    }

    @Override
    public Shop findById(Long id){
        return  baseMapper.selectById(id);
    }
}
